package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.po.ShoppingCartPO;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.LifecycleState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Content:
 * @Author: Asen
 * @Date: 2023/9/8 15:21
 */
@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "用户端购物车功能")
@Slf4j
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result add(@RequestBody ShoppingCartDTO source){
        shoppingCartService.add(source);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("获取当前用户购物车内容")
    public Result<List<ShoppingCartPO>> list(){
        return Result.success(shoppingCartService.list());
    }

    @PostMapping("/sub")
    @ApiOperation("减少购物车物品")
    public Result sub(@RequestBody ShoppingCartDTO source){
        shoppingCartService.sub(source);
        return Result.success();
    }

    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result clean(){
        shoppingCartService.clean();
        return Result.success();
    }
}
